package net.huashitong.dataHailCtrl;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.utils.NumberUtils;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.Project.entity.NewProjects;
import net.huashitong.Project.filter.NewProjectsFilter;
import net.huashitong.Project.responseModel.ItemResponseModel;
import net.huashitong.Project.service.EarlyWarningNodeService;
import net.huashitong.Project.service.NewProjectsService;
import net.huashitong.node.entity.NodeNewschedules;
import net.huashitong.node.service.NodeNewschedulesService;
import net.huashitong.user.service.LoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/zd_data")
public class DataHailCtrl extends JsonBaseController {

    @Autowired
    private NewProjectsService newProjectsService;
    @Autowired
    private LoginLogService loginLogService;
    @Autowired
    private NodeNewschedulesService nodeNewschedulesService;
    @Autowired
    private EarlyWarningNodeService earlyWarningNodeService;

    @Override
    protected String getView(String s) {
        return null;
    }

    /**
     * 重大项目、新开项目、结转项目投资统计
     *
     * @return
     * @throws ParseException
     */
    @ResponseBody
    @RequestMapping(value = "/getProjectInfo", method = RequestMethod.GET)
    public List<Map<String, Object>> getProjectInfo() {
        List<Map<String, Object>> result = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        for (int i = 0; i < 3; i++) {
            Map<String, Object> m = new HashMap<>();
            String ProjectType;
            Map<String, Object> oneMap;
            if (i == 0) {
                ProjectType = "重大";
                oneMap = newProjectsService.getStarOrNotWorkMap(null);
            } else if (i == 1) {
                ProjectType = "新开";
                oneMap = newProjectsService.getStarOrNotWorkMap("2001");
            } else {
                ProjectType = "结转";
                oneMap = newProjectsService.getStarOrNotWorkMap("2002");
            }
            //投资额（万元）
            String moneyStr = (String) oneMap.get("plannedInvestment");
            BigDecimal Money = new BigDecimal(moneyStr);
            //开工数
            int LargeAmount = (Integer) oneMap.get("startWorkNum");
            //开工率（保留一位小数）
            String StartRatioStr = (String) oneMap.get("startWorkRate");
            StartRatioStr = StartRatioStr.replace("%", "");
            double StartRatio = Double.parseDouble(StartRatioStr);
            m.put("Money", Money);
            m.put("LargeAmount", LargeAmount);
            m.put("StartRatio", StartRatio);
            m.put("ProjectType", ProjectType);
            m.put("Time", time);
            result.add(m);
        }
        return result;
    }


    /**
     * 重大项目、新开项目、结转项目开工对比
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProjectState", method = RequestMethod.GET)
    public List<Map<String, Object>> getProjectState() {
        List<Map<String, Object>> result = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        for (int i = 0; i < 3; i++) {
            String ProjectType;
            Map<String, Object> oneMap;
            if (i == 0) {
                ProjectType = "重大";
                oneMap = newProjectsService.getStarOrNotWorkMap(null);
            } else if (i == 1) {
                ProjectType = "新开";
                oneMap = newProjectsService.getStarOrNotWorkMap("2001");
            } else {
                ProjectType = "结转";
                oneMap = newProjectsService.getStarOrNotWorkMap("2002");
            }
            //StateAmount
            int StateAmount;
            String StartType;
            Map<String, Object> m1 = new HashMap<>();
            StateAmount = (Integer) oneMap.get("startWorkNum");
            StartType = "开工";
            m1.put("StateAmount", StateAmount);
            m1.put("StartType", StartType);
            m1.put("ProjcetType", ProjectType);
            m1.put("Time", time);
            result.add(m1);

            Map<String, Object> m2 = new HashMap<>();
            StateAmount = (Integer) oneMap.get("notStartWorkNum");
            StartType = "未开工";
            m2.put("StateAmount", StateAmount);
            m2.put("StartType", StartType);
            m2.put("ProjcetType", ProjectType);
            m2.put("Time", time);
            result.add(m2);
        }
        return result;
    }


    /**
     * 重大项目行业分类
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProjectTrade", method = RequestMethod.GET)
    public List<Map<String, Object>> getProjectTrade() {
        List<Map<String, Object>> result = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        Map<String, Object> map = newProjectsService.queryIndustryInfo();
        List<NewProjectsFilter> list = (List<NewProjectsFilter>) map.get("industry");
        for (NewProjectsFilter pro : list) {
            Map<String, Object> map1 = new HashMap<>();
            String TradeType = pro.getIndustryType();
            if ("旅游特色小镇项目".equals(TradeType)) {
                TradeType = TradeType.replace("项目", "");
            }
            BigInteger ProjectAmount = pro.getNum();
            Integer Ratio = pro.getPage();
            map1.put("TradeType", TradeType);
            map1.put("ProjectAmount", ProjectAmount);
            map1.put("Ratio", Ratio);
            map1.put("Time", time);
            result.add(map1);
        }
        return result;
    }


    /**
     * 重大项目点击排名
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getClickAmountSummary", method = RequestMethod.GET)
    public List<Map<String, Object>> getClickAmountSummary() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        Map<String, Integer> result = loginLogService.queryDeptLoginCount();
        Map<String, Integer> other = loginLogService.queryLoginCount();
        result.putAll(other);
        Map<String, Integer> clickCount = new LinkedHashMap<>();
        /*String[] branchs = {"国土局", "住建局", "发改局", "环保局", "水利局", "林业局", "财政局",  "消防大队", "人防办",
                "人社局", "业主单位", "攻坚办"};*/
        List<Map<String, Object>> result1 = new ArrayList<>();
        String[] branchs = {
                "永泰县自然资源和规划局",
                "永泰县住房和城乡建设局",
                "永泰县发展改革局",
                "永泰县生态环境局",
                "永泰县水利局",
                "永泰县林业局",
                "永泰县财政局",
                "永泰县公安消防大队",
                "永泰县人民防空办公室",
                "永泰县人力资源和社会保障局",
                "县重点工作攻坚指挥室",
                "业主单位"
        };
        List<String> branchList = Arrays.asList(branchs);
        for (Map.Entry<String, Integer> entry : result.entrySet()) {
            String key = entry.getKey();
            switch (key) {
                case "永泰县自然资源和规划局":
                    key = "国土局";
                    break;
                case "永泰县住房和城乡建设局":
                    key = "住建局";
                    break;
                case "永泰县发展改革局":
                    key = "发改局";
                    break;
                case "永泰县生态环境局":
                    key = "环保局";
                    break;
                case "永泰县水利局":
                    key = "水利局";
                    break;
                case "永泰县林业局":
                    key = "林业局";
                    break;
                case "永泰县财政局":
                    key = "财政局";
                    break;
                case "永泰县公安消防大队":
                    key = "消防大队";
                    break;
                case "永泰县人民防空办公室":
                    key = "人防办";
                    break;
                case "永泰县人力资源和社会保障局":
                    key = "人社局";
                    break;
                case "县重点工作攻坚指挥室":
                    key = "攻坚办";
                    break;
                case "业主单位":
                    key = "业主单位";
                    break;
                default:
                    key = "";
                    break;
            }

            if (StringUtils.isNotBlank(key)) {
                clickCount.put(key, entry.getValue());
            }
        }
        for (String branch : branchList) {
            if (ObjectUtils.isBlank(result.get(branch))) {
                clickCount.put(branch, 0);
            }
        }
        // 升序比较器
        Comparator<Map.Entry<String, Integer>> valueComparator = new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getValue() - o2.getValue();
            }
        };
        // map转换成list进行排序
        List<Map.Entry<String, Integer>> list = new ArrayList<>(clickCount.entrySet());
        // 排序
        Collections.sort(list, valueComparator);
        for (Map.Entry<String, Integer> stringIntegerEntry : list) {
            Map<String, Object> map = new HashMap<>();
            String DepaName = stringIntegerEntry.getKey();
            int ClickAmount = stringIntegerEntry.getValue();
            map.put("DepaName", DepaName);
            map.put("ClickAmount", ClickAmount);
            map.put("Time", time);
            result1.add(map);
        }
        return result1;
    }


    /**
     * 重大项目性质分类
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProjectNature", method = RequestMethod.GET)
    public List<Map<String, Object>> getProjectNature() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        List<Map<String, Object>> result = new ArrayList<>();
        int a1 = newProjectsService.getProjectsByNatureTypeDetail("政府投资房建市政类");
        int a2 = newProjectsService.getProjectsByNatureTypeDetail("政府投资交通水利类");
        int a3 = newProjectsService.getProjectsByNatureTypeDetail("企业投资类");
        int a4 = newProjectsService.getProjectsByNatureTypeDetail("土地收储类");
        Map<String, Object> map1 = new HashMap<>();
        map1.put("Time", time);
        map1.put("Amount", a1);
        map1.put("NatureType", "政府投资房建市政类");
        result.add(map1);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("Time", time);
        map2.put("Amount", a2);
        map2.put("NatureType", "政府投资交通水利类");
        result.add(map2);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("Time", time);
        map3.put("Amount", a3);
        map3.put("NatureType", "企业投资类");
        result.add(map3);
        Map<String, Object> map4 = new HashMap<>();
        map4.put("Time", time);
        map4.put("Amount", a4);
        map4.put("NatureType", "土地收储类");
        result.add(map4);
        return result;
    }

    /**
     * 计划投资实际投资
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getInveComp", method = RequestMethod.GET)
    public List<Map<String, Object>> getInveComp() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        List<Map<String, Object>> result = new ArrayList<>();
        //重大项目
        Map<String, Object> oneMap1 = newProjectsService.getStarOrNotWorkMap(null);
        //年度计划
        Map<String, Object> oneMap2 = newProjectsService.getStarOrNotWorkMap("2001");

        Map<String, Object> map1 = new HashMap<>();
        //重大项目投资额（万元）
        String moneyStr1 = (String) oneMap1.get("plannedInvestment");
        BigDecimal Money1 = new BigDecimal(moneyStr1);
        map1.put("Money", Money1);
        map1.put("CompType", "重大项目投资额");
        map1.put("Time", time);
        result.add(map1);

        Map<String, Object> map2 = new HashMap<>();
        //年度计划投资额（万元）
        String moneyStr2 = (String) oneMap2.get("plannedInvestment");
        BigDecimal Money2 = new BigDecimal(moneyStr2);
        map2.put("Money", Money2);
        map2.put("CompType", "年度计划投资额");
        map2.put("Time", time);
        result.add(map2);

        return result;
    }


    /**
     * 重大项目开工率
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProjectPhase", method = RequestMethod.GET)
    public List<Map<String, Object>> getProjectPhase() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        List<Map<String, Object>> result = new ArrayList<>();

        //重大项目 (重大项目开工率)
        Map<String, Object> oneMap1 = newProjectsService.getStarOrNotWorkMap(null);
        //开工率
        String rate = (String) oneMap1.get("startWorkRate");
        rate = rate.replace("%", "");
        double PhasRatio = Double.parseDouble(rate);

        Map<String, Object> map1 = new HashMap<>();
        map1.put("PhaseName", "重大项目开工率");
        map1.put("PhasRatio", PhasRatio);
        map1.put("Time", time);
        result.add(map1);

        Map<String, Object> map2 = new HashMap<>();
        map2.put("PhaseName", "项目投资完成率");
        map2.put("PhasRatio", 68.71);
        map2.put("Time", time);
        result.add(map2);

        Map<String, Object> map3 = new HashMap<>();
        map3.put("PhaseName", "交地完成率");
        map3.put("PhasRatio", 49.28);
        map3.put("Time", time);
        result.add(map3);

        Map<String, Object> map4 = new HashMap<>();
        map4.put("PhaseName", "拆迁完成率");
        map4.put("PhasRatio", 54.36);
        map4.put("Time", time);
        result.add(map4);

        return result;
    }


    /**
     * 各单位节点完成率
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getUnitPointFinish", method = RequestMethod.GET)
    public List<Map<String, Object>> getUnitPointFinish() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        List<Map<String, Object>> result = new ArrayList<>();
        Map<String, Object> map = nodeNewschedulesService.getAllDeptNodeCompletionRate();

        for (Map.Entry<String, Object> entry : map.entrySet()) {
            Map<String, Object> m = new HashMap<>();
            String mapKey = entry.getKey();
            Object mapValue = entry.getValue();
            Double ratio = (Double) mapValue;
            Double ratio1 = NumberUtils.doubleFormat(ratio, 2);
            m.put("UnitName", mapKey);
            m.put("Time", time);
            m.put("FinishRatio", ratio1);
            result.add(m);
        }
        return result;
    }


    /**
     * 各单位节预警信息处理率
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getUnitWarningDisposeFinish", method = RequestMethod.GET)
    public List<Map<String, Object>> getUnitWarningDisposeFinish() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        List<Map<String, Object>> result = new ArrayList<>();
        Map<String, Object> map = earlyWarningNodeService.queryEarlyWarningStateByDept();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            Map<String, Object> m = new HashMap<>();
            String mapKey = entry.getKey();
            Object mapValue = entry.getValue();
            Double ratio = (Double) mapValue;
            Double ratio1 = NumberUtils.doubleFormat(ratio, 2);
            m.put("UnitName", mapKey);
            m.put("Time", time);
            m.put("FinishRatio", ratio1);
            result.add(m);
        }
        return result;
    }


    /**
     * 重大项目节点完成情况
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProjectPointFinish", method = RequestMethod.GET)
    public List<Map<String, Object>> get_ProjectPointFinish() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        NewProjectsFilter filter = new NewProjectsFilter();
        //获取所有项目
        List<NewProjects> list = newProjectsService.getProjectInfo3(filter);
        List<Map<String, Object>> result = new ArrayList<>();

        //获取小节点，已确定
        List<NodeNewschedules> allNode = nodeNewschedulesService.getNodeInfo(null, "2", null, "1");

        Map<String, List<NodeNewschedules>> nodeMap = new HashMap<>();           //所有节点
        Map<String, List<NodeNewschedules>> nodeFinishedMap = new HashMap<>();   //完成节点
        Map<String, List<NodeNewschedules>> nodeBeginedMap = new HashMap<>();    //已开始
        Map<String, List<NodeNewschedules>> nodeNoMap = new HashMap<>();         //未开始

        for (NewProjects project : list) {
            List<NodeNewschedules> newNewschedules = new ArrayList<>();         //所有节点
            List<NodeNewschedules> newNewschedulesFinisted = new ArrayList<>(); //完成节点
            List<NodeNewschedules> newNewschedulesBegined = new ArrayList<>();  //已开始
            List<NodeNewschedules> newNewschedulesNo = new ArrayList<>();       //未开始
            for (NodeNewschedules node : allNode) {
                if (project.getSysId().equals(node.getProjectId())) {
                    newNewschedules.add(node);
                    if ("2".equals(node.getStatus())) {  //已完成
                        newNewschedulesFinisted.add(node);
                    }
                    if ("1".equals(node.getStatus())) {  //已开始
                        newNewschedulesBegined.add(node);
                    }
                    if ("0".equals(node.getStatus())) {  //未开始
                        newNewschedulesNo.add(node);
                    }
                }
            }
            nodeMap.put(project.getSysId(), newNewschedules);
            nodeFinishedMap.put(project.getSysId(), newNewschedulesFinisted);
            nodeBeginedMap.put(project.getSysId(), newNewschedulesBegined);
            nodeNoMap.put(project.getSysId(), newNewschedulesNo);
        }
        for (NewProjects newProject : list) {
            String projectId = newProject.getSysId();
            //遍历查询每个项目下的所有节点
            //需要的所有小节点
            List<NodeNewschedules> allNeed = nodeMap.get(newProject.getSysId());
            //完成的小节点:status=2
            List<NodeNewschedules> allFinishNeed = nodeFinishedMap.get(newProject.getSysId());
            //已开始小节点数
            List<NodeNewschedules> allBeginNeed = nodeBeginedMap.get(newProject.getSysId());
            //未开始小节点数
            List<NodeNewschedules> allNoBeginNeed = nodeNoMap.get(newProject.getSysId());
            //已开始
            if (allBeginNeed.size() > 0){
                NodeNewschedules node = allBeginNeed.get(0);
                Map<String, Object> map = new HashMap<>();
                map.put("Project", newProject.getName());
                map.put("Point", node.getNodeId()+" "+node.getNodeName()+"节点");
                map.put("PlanStart", StringUtils.isNotBlank(node.getPlanBeginDate())?(
                        node.getPlanBeginDate().replace(".","-")+" "+node.getUpdTime()):""
                        );
                map.put("RealStart", StringUtils.isNotBlank(node.getPlanBeginDate())?(
                        node.getPlanBeginDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("PlanFinish", StringUtils.isNotBlank(node.getFactFinishDate())?(
                                node.getFactFinishDate().replace(".","-")+" "+node.getUpdTime()):""
                        );
                map.put("RealFinish", StringUtils.isNotBlank(node.getFactFinishDate())?(
                        node.getFactFinishDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("PlanDays", StringUtils.isNotBlank(node.getPlanTime())?Integer.parseInt(node.getPlanTime()):0);
                map.put("RealDays", StringUtils.isNotBlank(node.getPlanTime())?Integer.parseInt(node.getPlanTime()):0);
                map.put("Time",time);
                result.add(map);
                continue;
            }
            //已完成
            if (allFinishNeed.size() > 0){
                NodeNewschedules node = allFinishNeed.get(0);
                Map<String, Object> map = new HashMap<>();
                map.put("Project", newProject.getName());
                map.put("Point", node.getNodeId()+" "+node.getNodeName()+"节点");
                map.put("PlanStart", StringUtils.isNotBlank(node.getPlanBeginDate())?(
                        node.getPlanBeginDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("RealStart", StringUtils.isNotBlank(node.getPlanBeginDate())?(
                        node.getPlanBeginDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("PlanFinish", StringUtils.isNotBlank(node.getFactFinishDate())?(
                        node.getFactFinishDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("RealFinish", StringUtils.isNotBlank(node.getFactFinishDate())?(
                        node.getFactFinishDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("PlanDays", StringUtils.isNotBlank(node.getPlanTime())?Integer.parseInt(node.getPlanTime()):0);
                map.put("RealDays", StringUtils.isNotBlank(node.getPlanTime())?Integer.parseInt(node.getPlanTime()):0);
                map.put("Time",time);
                result.add(map);
                continue;
            }
            //未完成
            if (allNoBeginNeed.size() > 0){
                NodeNewschedules node = allNoBeginNeed.get(0);
                Map<String, Object> map = new HashMap<>();
                map.put("Project", newProject.getName());
                map.put("Point", node.getNodeId()+" "+node.getNodeName()+"节点");
                map.put("PlanStart", StringUtils.isNotBlank(node.getPlanBeginDate())?(
                        node.getPlanBeginDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("RealStart", StringUtils.isNotBlank(node.getPlanBeginDate())?(
                        node.getPlanBeginDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("PlanFinish", StringUtils.isNotBlank(node.getFactFinishDate())?(
                        node.getFactFinishDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("RealFinish", StringUtils.isNotBlank(node.getFactFinishDate())?(
                        node.getFactFinishDate().replace(".","-")+" "+node.getUpdTime()):""
                );
                map.put("PlanDays", StringUtils.isNotBlank(node.getPlanTime())?Integer.parseInt(node.getPlanTime()):0);
                map.put("RealDays", StringUtils.isNotBlank(node.getPlanTime())?Integer.parseInt(node.getPlanTime()):0);
                map.put("Time",time);
                result.add(map);
                continue;
            }
        }
        return result;
    }



    /**
     * 重大项目节点完成情况(11)
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getProjectList", method = RequestMethod.GET)
    public List<Map<String, Object>> getProjectList() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(new Date());
        NewProjectsFilter filter = new NewProjectsFilter();
        //获取所有项目
        List<NewProjects> list = newProjectsService.getProjectInfo3(filter);
        List<Map<String, Object>> result = new ArrayList<>();

        //获取小节点，已确定
        List<NodeNewschedules> allNode = nodeNewschedulesService.getNodeInfo(null, "2", null, "1");

        Map<String, List<NodeNewschedules>> nodeMap = new HashMap<>();           //所有节点
        Map<String, List<NodeNewschedules>> nodeFinishedMap = new HashMap<>();   //完成节点
        Map<String, List<NodeNewschedules>> nodeBeginedMap = new HashMap<>();    //已开始
        Map<String, List<NodeNewschedules>> nodeNoMap = new HashMap<>();         //未开始

        for (NewProjects project : list) {
            List<NodeNewschedules> newNewschedules = new ArrayList<>();         //所有节点
            List<NodeNewschedules> newNewschedulesFinisted = new ArrayList<>(); //完成节点
            List<NodeNewschedules> newNewschedulesBegined = new ArrayList<>();  //已开始
            List<NodeNewschedules> newNewschedulesNo = new ArrayList<>();       //未开始
            for (NodeNewschedules node : allNode) {
                if (project.getSysId().equals(node.getProjectId())) {
                    newNewschedules.add(node);
                    if ("2".equals(node.getStatus())) {  //已完成
                        newNewschedulesFinisted.add(node);
                    }
                    if ("1".equals(node.getStatus())) {  //已开始
                        newNewschedulesBegined.add(node);
                    }
                    if ("0".equals(node.getStatus())) {  //未开始
                        newNewschedulesNo.add(node);
                    }
                }
            }
            nodeMap.put(project.getSysId(), newNewschedules);
            nodeFinishedMap.put(project.getSysId(), newNewschedulesFinisted);
            nodeBeginedMap.put(project.getSysId(), newNewschedulesBegined);
            nodeNoMap.put(project.getSysId(), newNewschedulesNo);
        }
        for (NewProjects newProject : list) {
            String projectId = newProject.getSysId();
            //遍历查询每个项目下的所有节点
            //需要的所有小节点
            List<NodeNewschedules> allNeed = nodeMap.get(newProject.getSysId());
            //完成的小节点:status=2
            List<NodeNewschedules> allFinishNeed = nodeFinishedMap.get(newProject.getSysId());
            //已开始小节点数
            List<NodeNewschedules> allBeginNeed = nodeBeginedMap.get(newProject.getSysId());
            //未开始小节点数
            List<NodeNewschedules> allNoBeginNeed = nodeNoMap.get(newProject.getSysId());

            Map<String, Object> map = new HashMap<>();
            map.put("ProjectName", newProject.getName());
            String industryType = newProject.getIndustryType();
            switch (industryType){
                case "1002": industryType = "工业项目"; break;
                case "1003": industryType = "交通"; break;
                case "1007": industryType = "商住项目"; break;
                case "1005": industryType = "安置房项目"; break;
                case "1006": industryType = "社会事业项目"; break;
                case "1004": industryType = "城镇基础设施"; break;
                case "1008": industryType = "农林水利环保生态项目"; break;
                case "1001": industryType = "旅游特色小镇项目"; break;
                default: industryType = "";break;
            }
            int noBeginNeed = allNeed.size() - allFinishNeed.size() - allBeginNeed.size();
            String ratio = NumberUtils.calculateRate(allFinishNeed.size(), allNeed.size(), 2);
            map.put("ProjectType", industryType);
            map.put("Manager", newProject.getResUser());
            map.put("Ratio", ratio.replace("%",""));
            map.put("Unit", newProject.getResDept());
            if (allBeginNeed.size() > 0){
                map.put("Point", allBeginNeed.get(0).getNodeId() + " " + allBeginNeed.get(0).getNodeName());
            }else{
                map.put("Point", "无");
            }
            map.put("Start", allBeginNeed.size());
            map.put("NoStart", noBeginNeed);
            map.put("Finish", allFinishNeed.size());
            map.put("Time",time);
            result.add(map);
        }
        return result;
    }
}
